package net.aiion.weave.spi.naming;

import java.util.ServiceLoader;

public abstract class GlobalContextFactory
{
    private static GlobalContextFactory mGlobalContextFactory;

    public GlobalContextFactory() {
    }

    public abstract GlobalContext createGlobalContext();

    public static GlobalContextFactory getInstance() {
        if (mGlobalContextFactory == null) {
            for (GlobalContextFactory globalContextFactory : GlobalContextFactoryServiceLoader.SERVICE_LOADER) {
                mGlobalContextFactory = globalContextFactory;
                break;
            }
        }

        return mGlobalContextFactory;
    }

    private static final class GlobalContextFactoryServiceLoader
    {
        private static final ServiceLoader<GlobalContextFactory> SERVICE_LOADER = ServiceLoader
            .load(GlobalContextFactory.class);

        private GlobalContextFactoryServiceLoader() {
        }
    }
}
